package org.spring.batch.ch06;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.batch.ch05.model.Group;
/**
 * 在Writer里面抛出异常：retry只会将writer过程重复指定的次数，不包含出错的那一次，重试指定次数后仍然失败，整个Job失败。<br>
 * skip时会将List里面的每一条数据拿出来跑writer过程，这样可以保证List里面一部分不出现异常的数据得到处理。<br>
 * skip-limit 和 retry-limit 都指定， 出现异常时，先重试，重试指定次数依然异常则跳过。
 * @author Administrator
 *
 */
public class RetryItemWriter implements org.springframework.batch.item.ItemWriter<Object> {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	public void write(List<? extends Object> items) throws Exception {
		logger.info("=====>>RetryItemWriter, Count={}", items.size());
		for (Object obj : items) {
			Group group = null;
			if (obj instanceof Group) {
				group = (Group) obj;
				logger.info("Group:{}", group);
				if (group.getId() == 30 || group.getId() == 35) {
					throw new IllegalArgumentException("抛个异常吧");
				}
			}
		}
	}

}
